package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo3 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //1.加载驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
        //2.获取连接
        System.out.println("正在链接数据库");
        Connection connection = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                "root",
                "root");
        System.out.println("链接数据库成功");
        //3.操作数据库
        System.out.println("正在操作数据库");
        Statement statement = connection.createStatement();
        String sql="delete from user where user.username='张三'";
        int num=statement.executeUpdate(sql);
        System.out.println(num>0?"成功执行"+num+"条数据":"执行失败");
        connection.close();
    }
}
